-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.cpp
More file actions
40 lines (32 loc) · 830 Bytes
/
Solution.cpp
File metadata and controls
40 lines (32 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
using namespace std;
void findDuplicates(vector<int> &arr) {
cout << "Duplicate elements: ";
bool found = false;
for (size_t i = 0; i < arr.size() - 1; i++) {
for (size_t j = i + 1; j < arr.size(); j++) {
if (arr[i] == arr[j]) {
cout << arr[i] << " ";
found = true;
break; // Avoid printing the same duplicate multiple times
}
}
}
if (!found) {
cout << "None";
}
cout << endl;
}
int main() {
int n;
cout << "Enter the number of elements in the array: ";
cin >> n;
vector<int> arr(n);
cout << "Enter the elements of the array:" << endl;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
findDuplicates(arr);
return 0;
}